<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Index extends MY_Controller {
	
	function __construct(){
		parent::__construct();
		$this->load->library('headassets');
		$this->load->driver('cache');
		$this->load->model('admin/admin_model');
	}
	
	function index(){
		$this->load->model('admin_model');
		if (!$this->admin_model->logged_in()) {
			$this->_redirect(admin_url('*/*/login'));
		}
		$this->_redirect(admin_url('*/dashboard/index'));
	}
	
	function logout(){
		$this->admin_model->logout();
		$this->_redirect(admin_url('*/index/login'));
	}
	
	function login(){
		if ($this->input->is_post()){
			$admin_username = $this->input->post('admin_user');
			$admin_password = $this->input->post('admin_pass');
			if ($this->admin_model->login($admin_username,$admin_password)){
				$this->_redirect(admin_url('*/dashboard/index'));
			}
		}
		$this->load->view('admin/login');
	}
}